//
//  NSStringExtensions.m
//  BeautyBaoUnion
//
//  Created by 肖智 on 2016/10/20.
//  Copyright © 2016年 肖智. All rights reserved.
//

#import "NSStringExtensions.h"

@implementation NSString(commonExt)
- (NSMutableAttributedString *)genAttributStringWithSpecialStrs:(NSArray *)strs
                                                    commonColor:(UIColor *)commoneColor
                                                   specialColor:(UIColor *)specialColor
                                                     commonFont:(UIFont *)commonFont
                                                    specialFont:(UIFont *)specialFont
                                                  textAlignment:(NSTextAlignment)alignment
                                                      lineSpace:(CGFloat)linespace{
    NSMutableAttributedString *dst = [[NSMutableAttributedString alloc] initWithString:self];
    [dst addAttribute:NSForegroundColorAttributeName value:commoneColor range:NSMakeRange(0, self.length)];
    [dst addAttribute:NSFontAttributeName value:commonFont range:NSMakeRange(0, self.length)];

    NSMutableParagraphStyle *p = [[NSMutableParagraphStyle alloc] init];
    p.lineSpacing = linespace;
    p.alignment = alignment;
    [dst addAttribute:NSParagraphStyleAttributeName value:p range:NSMakeRange(0, self.length)];
    for(NSString *str in strs){
        NSRange range = [self rangeOfString:str];
        if(range.length != 0){
            [dst addAttribute:NSForegroundColorAttributeName value:specialColor range:range];
            [dst addAttribute:NSFontAttributeName value:specialFont range:range];

        }
    }
    return dst;
}
@end
